package com.bootx.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.elasticsearch.ElasticsearchEmbeddingStore;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static dev.langchain4j.internal.ValidationUtils.ensureNotNull;

/**
 * @author black
 */
@Configuration
public class EmbeddingStoreConfig {

    @Bean(name = "elasticsearchEmbeddingStore")
    public EmbeddingStore<TextSegment> elasticsearchEmbeddingStore(){
        RestClientBuilder restClientBuilder = RestClient
                .builder(HttpHost.create(ensureNotNull("http://localhost:9200", "serverUrl")));
        return ElasticsearchEmbeddingStore.builder()
                .indexName("embedding")
                .restClient(restClientBuilder.build())
                .build();
    }

}
